/**
 * SpringMVC restful 风格
 * 网站首页控制器，控制关于网站首页的一些业务逻辑操作
 * @author yanwl
 * @date 2014-08-20
 */
package com.chnbst.bstyun.controller.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.chnbst.bstyun.model.pojo.Menu;
import com.chnbst.bstyun.model.pojo.User;
import com.chnbst.bstyun.service.MenuService;

@Controller
public class IndexController {
	/**
	 * 注入 业务逻辑层
	 */
	@Autowired
	private MenuService menuService;
	
	/**
	 * http://xxx.com/index
	 * get请求 默认返回网站首页
	 */
	@RequestMapping(value="",method=RequestMethod.GET)
	public ModelAndView index(HttpServletRequest request){
		List<Menu> menus = menuService.selectMenus();
		ModelAndView mav = new ModelAndView();
		HttpSession session = request.getSession();
		User user = (User)session.getAttribute("userInfo");
		if(user!=null){
			String loginWay = (String)session.getAttribute("loginWay");
			mav.addObject("user",user);
			mav.addObject("loginWay",loginWay);
		}
		mav.addObject("menus", menus);
		mav.setViewName("mall/index");
		return mav;
	}	
}
